<?php

namespace App\Containers\AppSection\File\Tasks;

use App\Containers\AppSection\File\Data\Criterias\DoesntHaveSignatureCriteria;
use App\Containers\AppSection\File\Data\Criterias\HasSignatureCriteria;
use App\Containers\AppSection\File\Data\Repositories\FileRepository;
use App\Ship\Criterias\IsNullCriteria;
use App\Ship\Criterias\NotNullCriteria;
use App\Ship\Criterias\ThisProfileCriteria;
use App\Ship\Criterias\Where;
use App\Ship\Parents\Tasks\Task;
use App\Ship\Traits\FilterByDateTrait;

class GetAllFilesTask extends Task
{
    use FilterByDateTrait;

    protected FileRepository $repository;

    public function __construct(FileRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run()
    {
        return $this->repository->paginate();
    }

    public function fromType($type): self
    {
        switch ($type) {
            case 'profile':
            {
                $this->repository->doesntHave('project')->has('sign')->pushCriteria(new HasSignatureCriteria());
                break;
            }
            case 'project':
            {
                $this->repository->has('project')->has('sign')->pushCriteria(new HasSignatureCriteria());
                break;
            }
            case 'signature':
            {
                $this->repository->has('project')->has('sign')->pushCriteria(new DoesntHaveSignatureCriteria());
                //$this->repository->has('project')->has('sign')->doesntHave('signature')->orWhereDoesntHave('confirmation');
                break;
            }
        }


        return $this;
    }

    public function thisProfile($profileId): self
    {
        $this->repository->pushCriteria(new ThisProfileCriteria($profileId));
        return $this;
    }
}
